package com.blueocean_health.care.management.service.order_service_info;

import java.math.BigDecimal;
import java.sql.Time;
import java.util.*;
import java.util.stream.Collectors;

import com.blueocean_health.care.management.common.base.string.StringUtils;
import com.blueocean_health.care.management.domain.base.*;
import com.blueocean_health.care.management.domain.dto.SelectCareSalarySummaryRespDto;
import com.blueocean_health.care.management.em.OrderFlagEnum;
import com.blueocean_health.care.management.em.OrderTimeTypeEnum;
import com.blueocean_health.care.management.em.OrderTypeEnum;
import com.blueocean_health.care.management.mapper.HospitalMapper;
import com.blueocean_health.care.management.mapper.TeamMapper;
import com.blueocean_health.care.management.util.Arith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blueocean_health.care.management.common.LocalManager;
import com.blueocean_health.care.management.common.base.em.TimeType;
import com.blueocean_health.care.management.common.base.time.TimeUtils;
import com.blueocean_health.care.management.domain.dto.SelectCareSalaryDbDto;
import com.blueocean_health.care.management.domain.dto.SelectCareSalaryDto;
import com.blueocean_health.care.management.domain.dto.SelectCareSalaryRespDto;
import com.blueocean_health.care.management.em.LocalManagerType;
import com.blueocean_health.care.management.exception.OrderServiceException;
import com.blueocean_health.care.management.mapper.OrderServiceNurseInfoMapper;

@Service
public class SelectCareSalaryServiceImpl implements SelectCareSalaryService {

    Logger logger = LoggerFactory.getLogger(SelectCareSalaryServiceImpl.class);
	
	@Autowired
	private OrderServiceNurseInfoMapper orderServiceNurseInfoMapper;

	@Autowired
    private HospitalMapper hospitalMapper;

    @Autowired
    private TeamMapper teamMapper;
	
	@Override
    public SysResult queryCareSalaryReport(SelectCareSalaryDto careSalaryDto) throws OrderServiceException {

        Date beginTime = TimeUtils.getDateByString(careSalaryDto.getBeginTime(),TimeType.yyyy_MM_dd);
        Date endTime = TimeUtils.getDateByString(careSalaryDto.getEndTime(),TimeType.yyyy_MM_dd);

        Long durationCount = getDatePoorOfDays(endTime,beginTime);

        List<SelectCareSalaryRespDto> dataList = queryCareSalaryReportExcel(careSalaryDto);
        if(dataList == null || dataList.size() == 0) {
            return SysResultByPage.ok(0,0,new ArrayList<>(), 0);
        }

        Double bonusCount = 0.0;
        bonusCount = dataList.stream().mapToDouble(dto -> Double.parseDouble(dto.getDayPay())).sum();

        //价格四舍五入，保留两位小数
        BigDecimal b = new BigDecimal(bonusCount);
        bonusCount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        List<SelectCareSalaryRespDto> resultList = new ArrayList<>();
        //开启手动分页模式
        int first = (careSalaryDto.getPage() - 1) * careSalaryDto.getPageSize();
        int end = (first + careSalaryDto.getPageSize() > dataList.size() ? dataList.size() : first + careSalaryDto.getPageSize());
        for (int i = first; i < end; i++) {
            resultList.add(dataList.get(i));
        }
        return SysResultByPage.ok(durationCount,bonusCount,resultList, dataList.size());
    }

    @Override
    public SysResult queryNurseSalarySummary(SelectCareSalaryDto careSalaryDto) throws OrderServiceException {

        Date beginTime = TimeUtils.getDateByString(careSalaryDto.getBeginTime(),TimeType.yyyy_MM_dd);
        Date endTime = TimeUtils.getDateByString(careSalaryDto.getEndTime(),TimeType.yyyy_MM_dd);
        Long durationCount = getDatePoorOfDays(endTime,beginTime);

        List<SelectCareSalarySummaryRespDto> result = this.queryNurseSalarySummaryExcel(careSalaryDto);

        if (result == null){
            return SysResultByPage.ok(durationCount,0,result, 0);
        }

        Double bonusCount = 0.0;
        bonusCount = result.stream().mapToDouble(dto -> Double.parseDouble(dto.getDayPay())).sum();

        //价格四舍五入，保留两位小数
        BigDecimal b = new BigDecimal(bonusCount);
        bonusCount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        result.forEach(dto -> dto.setDayPayDouble(Double.parseDouble(dto.getDayPay())));

        //排序
        if (!StringUtils.isEmpty(careSalaryDto.getSort())){
            if ("dayPay asc".equals(careSalaryDto.getSort())){
                result.sort((o1, o2) -> o1.getDayPayDouble().compareTo(o2.getDayPayDouble()));
            }else {
                result.sort((o1, o2) -> o2.getDayPayDouble().compareTo(o1.getDayPayDouble()));
            }
        }

        List<SelectCareSalarySummaryRespDto> resultList = new ArrayList<>();
        //开启手动分页模式
        int first = (careSalaryDto.getPage() - 1) * careSalaryDto.getPageSize();
        int end = (first + careSalaryDto.getPageSize() > result.size() ? result.size() : first + careSalaryDto.getPageSize());
        for (int i = first; i < end; i++) {
            resultList.add(result.get(i));
        }
        return SysResultByPage.ok(durationCount,bonusCount,resultList, result.size());
    }

    @Override
    public List<SelectCareSalarySummaryRespDto> queryNurseSalarySummaryExcel(SelectCareSalaryDto careSalaryDto) throws OrderServiceException {
        careSalaryDto.setOutWorkerKey("");
        careSalaryDto.setPatientKey("");
        careSalaryDto.setOrderId("");
        //careSalaryDto.setSort("");



        String sbeginTime = careSalaryDto.getBeginTime().replaceAll("-","/");
        String sendTime = careSalaryDto.getEndTime().replaceAll("-","/");

        List<SelectCareSalaryRespDto> dataList = queryCareSalaryReportExcel(careSalaryDto);
        if(dataList == null || dataList.size() == 0) {
            return null;
        }

        List<SelectCareSalarySummaryRespDto> result = new ArrayList<>();

        dataList.stream()
                .collect(Collectors.groupingBy(o -> o.getWorkId()))
                .forEach((workid, selectCareSalaryRespDtos) -> {
                    SelectCareSalarySummaryRespDto respDto = new SelectCareSalarySummaryRespDto();
                    respDto.setWorkId(workid);
                    respDto.setWorkingDay(sbeginTime+" - "+sendTime);


                    respDto.setWorkName(selectCareSalaryRespDtos.get(0).getWorkName());

                    Double money = 0.00;
                    money = selectCareSalaryRespDtos.stream().mapToDouble(dto -> Double.parseDouble(dto.getDayPay())).sum();
                    //整数不保留
                    int intValue = 0;
                    if (money.intValue() == money) {
                        intValue = money.intValue();
                    }else{
                        //价格四舍五入，保留两位小数
                        BigDecimal b = new BigDecimal(money);
                        money = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    }

                    if (intValue != 0){
                        respDto.setDayPay(intValue+"");
                        result.add(respDto);
                    }else if (money != 0){
                        respDto.setDayPay(money+"");
                        result.add(respDto);
                    } else {
                        respDto.setDayPay(0+"");
                        result.add(respDto);
                    }
                });

        return result;
    }

    @Override
	public List<SelectCareSalaryRespDto> queryCareSalaryReportExcel(SelectCareSalaryDto careSalaryDto) throws OrderServiceException {
		String nowDay = TimeUtils.getTime(TimeType.yyyy_MM_dd);
		if(careSalaryDto.getBeginTime() == null || !TimeUtils.validate(careSalaryDto.getBeginTime(), TimeType.yyyy_MM_dd)) {
			careSalaryDto.setBeginTime(nowDay + " 00:00:00");
		}
		else {
			careSalaryDto.setBeginTime(careSalaryDto.getBeginTime() + " 00:00:00");
		}
		if(careSalaryDto.getEndTime() == null || !TimeUtils.validate(careSalaryDto.getEndTime(), TimeType.yyyy_MM_dd)) {
			careSalaryDto.setEndTime(nowDay + " 00:00:00");
		}
		else {
			careSalaryDto.setEndTime(careSalaryDto.getEndTime() + " 00:00:00");
		}
		Calendar _end = Calendar.getInstance();
        _end.setTime(TimeUtils.getDateByString(careSalaryDto.getEndTime(), TimeType.yyyy_MM_dd_HH_mm_ss));
		_end.add(Calendar.DAY_OF_YEAR, 1);
		careSalaryDto.setEndTime(TimeUtils.getStringByDate(_end.getTime(), TimeType.yyyy_MM_dd_HH_mm_ss));
		
		List<SelectCareSalaryDbDto> careSalaryList = orderServiceNurseInfoMapper.selectNurseSalaryByTime(careSalaryDto);
		
		if(careSalaryList == null || careSalaryList.size() == 0){
//			throw new OrderServiceException("query no data");
			return new ArrayList<>();
		}
		
		User user = LocalManager.getVal(LocalManagerType.USER_WEB);
		String hospital = user.getHospitalId();

		/*
			胸科从后往前
		* 	boolean endWay = "1".equals(hospital);
		* */
		//胸科从前往后
        final Team hospitalInfo = teamMapper.getTeamById(hospital);
        boolean endWay = hospitalInfo.getCountMethod() == 11 ||hospitalInfo.getCountMethod() == 12;
        //boolean endWay = "2".equals(hospital) || "3".equals(hospital) || "4".equals(hospital);
		Date beginTime = TimeUtils.getDateByString(careSalaryDto.getBeginTime(), TimeType.yyyy_MM_dd_HH_mm_ss);
		Date endTime = TimeUtils.getDateByString(careSalaryDto.getEndTime(), TimeType.yyyy_MM_dd_HH_mm_ss);
		
		List<SelectCareSalaryRespDto> dataList = new ArrayList<>();
		
		for (SelectCareSalaryDbDto dto : careSalaryList) {

		    if (StringUtils.isEmpty(dto.getOrderType())){
		        throw  new OrderServiceException("数据ordertype字段为空");
            }
		    //判断该订单是否是退款单
            Boolean isRefundOrder = false;
            if (OrderTypeEnum._3.getKey().equals(dto.getOrderType())){
                isRefundOrder = true;
            }

            //单价非空判断（外勤端测试数据会出现null的情况）
            if(dto.getOneHourPay() == null){
                continue;
            }

            TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
			Calendar cStartTime = Calendar.getInstance();

            //有退款情况，按退款的实际截止时间
            if (dto.getRefundTime()!=null) {
                //退款时间小于等于开始时间，跳过不计算
                if (dto.getRefundTime().getTime() <= dto.getStartTime().getTime()){
                    continue;
                }
                //退款时间只有在该订单的服务时间内才去计算（防止同一个订单，多个明细不同护工导致计算错误）
                if(dto.getRefundTime().getTime() > dto.getStartTime().getTime() && dto.getRefundTime().getTime() <= dto.getEndTime().getTime()){
                    dto.setEndTime(dto.getRefundTime());
                }
            }

			String zeroStartTime = TimeUtils.getStringByDate(dto.getStartTime(),TimeType.yyyy_MM_dd)+" 00:00:00.000";
			String zeroEndTime = TimeUtils.getStringByDate(dto.getEndTime(),TimeType.yyyy_MM_dd)+" 00:00:00.000";

            Date zeroSdate = TimeUtils.getDateByString(zeroStartTime, TimeType.yyyy_MM_dd_HH_mm_ss_SSS);
            Date zeroEdate = TimeUtils.getDateByString(zeroEndTime, TimeType.yyyy_MM_dd_HH_mm_ss_SSS);

            cStartTime.setTime(TimeUtils.getDateByString(zeroStartTime,TimeType.yyyy_MM_dd_HH_mm_ss_SSS));
            Calendar cEndTime = Calendar.getInstance();

            Date dtoendDate = dto.getEndTime();
            cEndTime.setTime(dtoendDate);

			//来一个有序的(便于DUBUG)Map存储一下拆分的时间
			Map<String, Integer> timeMap = new TreeMap<>();
            Date dtoEndDate = TimeUtils.getDateByString(careSalaryDto.getEndTime(), TimeType.yyyy_MM_dd_HH_mm_ss);
            int i = 1;

            if (!endWay){
                if (zeroSdate.getTime() != zeroEdate.getTime()) {
                    cStartTime.add(Calendar.DAY_OF_YEAR, 1);
                }
            }

            while(true){
				if(!validateTime(cStartTime.getTime(), beginTime, endTime)){
				    //如果开始时间不在筛选时间内, 加一天看看
					if(TimeUtils.compare(endTime, cStartTime.getTime())) {
					    //如果时间大于结束时间, 跳出
						break;
					}
				}else{
					timeMap.put(TimeUtils.getStringByDate(cStartTime.getTime(), TimeType.yyyy_MM_dd), i++);
				}
				cStartTime.add(Calendar.DAY_OF_YEAR, 1);
				if(cStartTime.getTime().getTime() > cEndTime.getTime().getTime() || cStartTime.getTime().getTime() >= dtoEndDate.getTime() ) { //如果时间大于结束时间, 跳出
					break;
				}
			}
			//处理一下开始时间和结束时间的问题
			String _s = TimeUtils.getStringByDate(dto.getStartTime(),TimeType.yyyy_MM_dd_HH_mm_ss).substring(0, 10);
            String _e = TimeUtils.getStringByDate(dtoendDate,TimeType.yyyy_MM_dd_HH_mm_ss).substring(0, 10);

            Date dtoStartZeroDate = TimeUtils.getDateByString(_s+" 00:00:00",TimeType.yyyy_MM_dd_HH_mm_ss);
            Date requestZeroDate = TimeUtils.getDateByString( careSalaryDto.getBeginTime(),TimeType.yyyy_MM_dd_HH_mm_ss);

            Date dtoEzeroDate = TimeUtils.getDateByString(_e+" 00:00:00",TimeType.yyyy_MM_dd_HH_mm_ss);
            Date requestEndZeroDate = TimeUtils.getDateByString( careSalaryDto.getEndTime(),TimeType.yyyy_MM_dd_HH_mm_ss);

            Calendar requestEndZeroCalendar = Calendar.getInstance();
            requestEndZeroCalendar.setTime(requestZeroDate);
            requestEndZeroCalendar.add(Calendar.DAY_OF_YEAR, -1);
            Date ddd = requestEndZeroCalendar.getTime();
            //前端传的开始时间是否包括（小于等于）当前dto的开始时间
            boolean timeflag = false;
            if (ddd.getTime() <= dtoStartZeroDate.getTime()){
                timeflag = true;
            }
            Boolean sff = ddd.getTime() == dtoStartZeroDate.getTime();

            //当前dto结束时间是否大于前端传入的查询条件中的结束时间
            boolean timeEndflag = false;
            if (requestEndZeroDate.getTime() >= dtoEzeroDate.getTime()){
                timeEndflag = true;
            }
            Boolean ff = requestEndZeroDate.getTime() == dtoEzeroDate.getTime();

			//零碎工作时间工资
            Double endDayPay = 0.00;
            //胸科医院，计算第一天和最后一天的零碎工作时间转换给第一天
            //五中心转换给最后一天
            /*
            * 最后一天工作时间+第一天工作时间-24
            * > 0 则不缩天，按小时工资
            * = 0 缩一整天，按日工资
            * < 0 缩一天，但是是零碎小时，算小时工资
            * */
            String endtime = TimeUtils.getStringByDate(dtoendDate,TimeType.yyyy_MM_dd_HH_mm_ss).substring(0, 10)+" 00:00:00";
            Date enddate = TimeUtils.getDateByString(endtime,TimeType.yyyy_MM_dd_HH_mm_ss);
            Double endhour = getDatePoor(dtoendDate,enddate);

            String starttime = TimeUtils.getStringByDate(dto.getStartTime(),TimeType.yyyy_MM_dd_HH_mm_ss).substring(0, 10)+" 00:00:00";
            Date startdate = TimeUtils.getDateByString(starttime,TimeType.yyyy_MM_dd_HH_mm_ss);
            Double starthour = 24 - getDatePoor(dto.getStartTime(),startdate);

            Double totlehour = endhour + starthour;
            Double surplushour = totlehour - 24;

            Integer timeType =  dto.getOrderTypeFlag();

            //服务时间 天.小时
            final String serviceDay = dto.getServiceDay();
            String[] split = serviceDay.split("\\.");
            Integer days = Integer.parseInt(split[0]);
            Integer hours = Integer.parseInt(split[1]);

            if (surplushour < 0 ){
                endDayPay = totlehour * dto.getOneHourPay();
                //12小时制
                if(OrderTimeTypeEnum._2.getKey().equals(timeType+"")){
                    if(surplushour == -12){
                        endDayPay = dto.getOneDayPay();
                    }else{
                        endDayPay = dto.getOneHourPay() * hours;
                    }
                }

                if (endWay){
                	timeMap.remove(_e);
				}
            } else if ( surplushour > 0) {
                endDayPay = surplushour * dto.getOneHourPay();
                //12小时制
                if(OrderTimeTypeEnum._2.getKey().equals(timeType+"")){
                    if(surplushour == 12){
                        endDayPay = dto.getOneDayPay();
                    }else {
                        endDayPay = dto.getOneHourPay() * hours;
                    }
                }

                if(!endWay){
                    //只有包括了dto的开始时间，才put最小值
                    if (timeflag){
                        timeMap.put(_s, Integer.MIN_VALUE);
                    }
                    if (sff){
                        timeMap.remove(_s);
                    }
                }else {
                    //当前dto结束时间是否大于前端传入的查询条件中的结束时间,大于的话才去put
                    if (timeEndflag) {
                        timeMap.put(_e, Integer.MAX_VALUE);
                    }
                    if (ff){
                        timeMap.remove(_e);
                    }
                }
            } else {
                endDayPay = dto.getOneDayPay();
                if (endWay){
                    timeMap.remove(_e);
                }
                //endDayPay = 0.00;
            }

            //整数不保留
            int intValue = 0;
            Double otherTotal = 0.0;
            /*if (endDayPay.intValue() == endDayPay) {
                intValue = endDayPay.intValue();
            }else{
                //价格四舍五入，保留两位小数
                BigDecimal b = new BigDecimal(endDayPay);
                endDayPay = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                //用减法算最后一天的工资（只有整天的时候才会有除不尽的情况）
                Double oneDayPay = dto.getOneDayPay();  //日工资
                Double totalPay = dto.getTotalPay();  //总工资
                //整天才会出现除不尽的情况
                if (days > 1 && hours == 0){
                    Double otherTotal = Arith.mul((days.doubleValue() - 1),oneDayPay);
                    endDayPay = Arith.sub(totalPay,otherTotal);
                }
            }*/

            //所有的订单，最后一天都用减法去算，最后一天的提成金额显示，用总提成金额-其他天的提成金额
            //价格四舍五入，保留两位小数
            BigDecimal b = new BigDecimal(endDayPay);
            endDayPay = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            //用减法算最后一天的工资
            Double oneDayPay = dto.getOneDayPay();  //日工资
            Double totalPay = dto.getTotalPay();  //总工资
            //整天，出现除不尽的情况
            if (days >= 1 && hours == 0){
                otherTotal = Arith.mul((days.doubleValue() - 1),oneDayPay);
                endDayPay = Arith.sub(totalPay,otherTotal);
            }else if (days >= 1 && hours != 0){
                //订单时长大于等于一天，最后一天是零碎时间
                otherTotal = Arith.mul((days.doubleValue() ),oneDayPay);
                endDayPay = Arith.sub(totalPay,otherTotal);
            }else if (days == 0 && hours != 0){
                //订单总时长小于一天
                endDayPay = totalPay;
            }

            //是否为整数，整数不保留小数点
            if (endDayPay.intValue() == endDayPay) {
                intValue = endDayPay.intValue();
            }


            //退款单把数据变为负数
            if (isRefundOrder){
                //全用减法算最后一天的话，正常的工资有可能出现负数，判断一下
                intValue = 0 - intValue;
                if (intValue > 0){
                    intValue = 0 -intValue;
                }
                endDayPay = 0 - endDayPay;
                if (endDayPay > 0){
                    endDayPay = 0 - endDayPay;
                }
            }


            List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(timeMap.entrySet());
            Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {
                //升序排序
				@Override
                public int compare(Map.Entry<String, Integer> o1,
                                   Map.Entry<String, Integer> o2) {
                    return o1.getValue().compareTo(o2.getValue());
                }
            });

            List<SelectCareSalaryRespDto> salaryRespDtos = new ArrayList<>();

			timeMap.forEach((k, v) -> {
				SelectCareSalaryRespDto resp = new SelectCareSalaryRespDto(dto);
				resp.setWorkingDay(k);
				//resp.setDayPay(v == 1 ? (dto.getOneHourPay() * Math.abs(diff))+"" : dto.getOneDayPay()+"");
                //判断是否为整数，为整数则只保留整数部分
                int intOneDayPay = dto.getOneDayPay().intValue();
                if (dto.getOneDayPay() == intOneDayPay){
                    resp.setDayPay(intOneDayPay+"");
                    //退款单金额为负数
                    if (OrderTypeEnum._3.getKey().equals(dto.getOrderType())){
                        resp.setDayPay((0 - intOneDayPay)+"");
                    }
                }else{
                    resp.setDayPay(dto.getOneDayPay()+"");
                    //退款单金额为负数
                    if (OrderTypeEnum._3.getKey().equals(dto.getOrderType())){
                        resp.setDayPay((0 - dto.getOneDayPay())+"");
                    }
                }
				resp.setWorkId(dto.getWorkId());
				resp.setWorkName(dto.getWorkName());
				resp.setReceiptNumber(dto.getReceiptNumber());
				resp.setDeptName(dto.getDeptName());
				resp.setOrderType(dto.getOrderType());
				resp.setServiceId(dto.getServiceId());
				String orderTypeName = null;
				if (OrderTypeEnum._1.getKey().equals(dto.getOrderType())){
                    orderTypeName = OrderTypeEnum._1.getVal();
                }else if (OrderTypeEnum._2.getKey().equals(dto.getOrderType())){
                    orderTypeName = OrderTypeEnum._2.getVal();
                }else {
                    orderTypeName = OrderTypeEnum._3.getVal();
                }
				resp.setOrderTypeName(orderTypeName);
                salaryRespDtos.add(resp);

			});

			if(salaryRespDtos.size()>0){
				if (endWay){
                    if (timeEndflag) {
                        if (!ff){
                            if (intValue != 0){
                                salaryRespDtos.get(salaryRespDtos.size() - 1).setDayPay(intValue + "");
                            }else {
                                salaryRespDtos.get(salaryRespDtos.size() - 1).setDayPay(endDayPay + "");
                            }
                        }
                        if (surplushour <= 0 ){
                            if (intValue != 0){
                                salaryRespDtos.get(salaryRespDtos.size() - 1).setDayPay(intValue + "");
                            }else {
                                salaryRespDtos.get(salaryRespDtos.size() - 1).setDayPay(endDayPay + "");
                            }
                        }
                    }
                }else{
                    //只有包括了dto的开始时间，才set计算出的零碎时间的工资
				    if (timeflag){
				        if (!sff){
                            if (intValue != 0){
                                salaryRespDtos.get(0).setDayPay(intValue+"");
                            }else {
                                salaryRespDtos.get(0).setDayPay(endDayPay+"");
                            }
                        }
                        if (surplushour <= 0 ){
                            if (intValue != 0){
                                salaryRespDtos.get(0).setDayPay(intValue+"");
                            }else {
                                salaryRespDtos.get(0).setDayPay(endDayPay+"");
                            }
                        }
                    }
                }

			}
            dataList.addAll(salaryRespDtos);
		}

		//排除金额为0的数据
       /* List<SelectCareSalaryRespDto> resultdataList = new ArrayList<>();
		dataList.forEach(dto -> {
		    if (Double.parseDouble(dto.getDayPay()) != 0){
                resultdataList.add(dto);
            }
        });*/

        Collections.sort(dataList);
		return dataList;
	}
	
	private static boolean validateTime (Date time, Date begin, Date end){
		return time.getTime() >= begin.getTime() && time.getTime() < end.getTime();
	}

    private static double getDatePoor(Date endDate, Date nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        double result = 0.00;
        if (min == 30){
            //只要出现多出半小时的，按整数一个小时算
            result = hour + 1;
        }else {
            result = hour;
        }
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        //return day + "天" + hour + "小时" + min + "分钟";
        return result;
    }

    private static long getDatePoorOfDays(Date endDate, Date nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;

        return day+1;
    }


    public static void main(String[] args) {
        Double a = 234.34;
        Double b = 39.06 ;
        Double c = 6.0;
        Double d = 1.0;

        double days = Arith.sub(c, d);
        double otherTotal = Arith.mul(days,b);
        double result = Arith.sub(a,otherTotal);

        double ddd = Arith.div(c,d);
        double eee = Arith.div(c,d,2);
        System.out.println(ddd);
        System.out.println(eee);

        System.out.println(result);


    }

}
